
var html_ = $(".add-hover .add-change ul.ul").html();
// 显示
function Initialization(){
	$(".add-hover .add-change ul.u").html("");
	$(".add-hover").show();
	$(".container").hide();
	$(".add-hover .add-change ul.ul").show();
	$(".add-hover .add-change ul").html(html_);
	$("div.left-return").attr("onclick","close_add()");
}



// 添加图片
	function add_img(a){

		var art = a?a:$(".add-hover h1 b").text();
		$(".add-hover h1").html("推荐<b>"+art+"</b>的相关作品");
		$(".add-hover .add-change ul").html("");
		var html = "";
		
		html += "<dd class=\"first\" onclick=\"online()\"><img src=\"./Public/Home/img/add/online.jpg\" /><h2>网络图片</h2></dd>";
		html += "<dd class=\"localhost\" onclick=\"localhost()\"><img src=\"./Public/Home/img/add/localhost.jpg\" /><h2>本地图片</h2></dd>";

		$(".add-hover .add-change ul").append(html);

		$("div.left-return").attr("onclick","Initialization()");
		$(".container").hide();
		$(".add-hover .add-change ul.ul").show();
	}


	// 添加本地图片
	function localhost(){

		$(".add-hover .add-change ul").html("");
		$(".add-hover .add-change ul.ul").hide();
		$(".container").show();
		$("div.left-return").attr("onclick","add_img()");

	}


	// 添加网页图片
	function online(){

		$(".add-hover .add-change ul").html("");
		var html = "";
		
		html += '<input type="text" placeholder="http://" class="online-link"/> <input type="button" onclick="online_img()" value="浏　览"/>';

		$(".add-hover .add-change ul").append(html);

		$("div.left-return").attr("onclick","add_img()");

	}

	// 删除图片
	function closeimg(el){
		el.parentNode.parentNode.remove();
	}





	// 添加在线图片
	function add_online_img(as,we){
		// alert(123123)
		$(".add-hover .add-change ul.ul").html("");
		var html = "";
		
		html += '<input type="text" placeholder="'+we+'" class="online-link"/> <input type="button" onclick="online_img()" value="浏　览"/>';

		html += '<div class="online-img" id="scolltop">';
		html += 	'<dl>';

		    html += '<dd><img src="http://localhost/t/Artwork/2016-07-08/577f65e9dd3ff.png" data-two="1" data-id="1" alt="artwe" onclick="click_img(this)"/></dd>';
		    html += '<dd><img src="http://localhost/t/Artwork/2016-07-08/577f6b9518660.png" data-two="1" data-id="2" alt="artwe" onclick="click_img(this)"/></dd>';
		    html += '<dd><img src="http://localhost/t/Artwork/2016-07-08/577f71d8c347b.jpg" data-two="1" data-id="3" alt="artwe" onclick="click_img(this)"/></dd>';
		    html += '<dd><img src="http://localhost/t/Artwork/2016-07-08/577f6d631e5fd.png" data-two="1" data-id="4" alt="artwe" onclick="click_img(this)"/></dd>';
		    html += '<dd><img src="http://localhost/t/Artwork/2016-07-08/577f65e9dd3ff.png" data-two="1" data-id="5" alt="artwe" onclick="click_img(this)"/></dd>';
		    html += '<dd><img src="http://localhost/t/Artwork/2016-07-08/577f65e9dd3ff.png" data-two="1" data-id="6" alt="artwe" onclick="click_img(this)"/></dd>';
		    html += '<dd><img src="http://localhost/t/Artwork/2016-07-08/577f71d8c347b.png" data-two="1" data-id="7" alt="artwe" onclick="click_img(this)"/></dd>';
		    html += '<dd><img src="http://localhost/t/Artwork/2016-07-08/577f6b9518660.png" data-two="1" data-id="8" alt="artwe" onclick="click_img(this)"/></dd>';
		    html += '<dd><img src="http://localhost/t/Artwork/2016-07-08/577f6d631e5fd.png" data-two="1" data-id="9" alt="artwe" onclick="click_img(this)"/></dd>';

		html += 	'</dl>';
		html += '</div>';
		html += '<br><br><div class="test"><ul id="ul_pics" class="ul_pics asd"></ul></div>';

		$(".add-hover .add-change ul.ul").append(html);
		

		$("div.left-return").attr("onclick","online()");

		$(".add-hover .add-change ul .test ").append('<input type="button" value="保存" onclick="save_more_online()" class="save-more">');
	}


	// 点击图片添加

	function click_img(ur){

		var kg = ur.getAttribute("data-two");

		if(kg==1){
			var tt = ur.getAttribute("src");
			var id = ur.getAttribute("data-id");
			
			ur.setAttribute("data-two","0");

	        var html ="";
	        html += '<li><div class="img"><p data-id="'+id+'" onclick="closeimgonline(this)">X</p><img src="'+tt+'" alt=""/> '
	        html += '<dl>';
	        html += '<dd> <span>分类</span> <select name="select" id="select_k1"> <option value="1">全部</option> <option value="2">分类2</option> <option value="3">分类3</option> </select> </dd> ';
	        html += '<dd> <span>标题</span><input type="text" class="title"/></dd>';
	        html += '<dd> <span>年份</span><input type="text" class="year" /></dd>';
	        html += '<dd> <span>材质</span><input type="text" class="material" /></dd>';
	        html += '<dd> <span>尺寸</span><input type="text" class="size" placeholder="公分"/></dd>';
	        html += '<dd> <span>简介</span> <textarea name="" id="" cols="150" rows="5" class="Blur-Messg"></textarea> </dd>';
	        html += '</dl>';
	        html += '</div></li>';
	        $(".add-hover .add-change ul .test ul.asd").append(html);

			$("div.left-return").attr("onclick","online()");

		}

	}




	// 删除图片
	function closeimgonline(el){
		el.parentNode.parentNode.remove();
		var cid = el.getAttribute("data-id");

		for(var i=0;i<10;i++){
			if(cid==i){
				$(".add-hover .add-change ul div.online-img dl dd").eq(i-1).find("img").attr("data-two","1");
				return false;
			}
		}

	}







// 添加文字

function add_words(a,b){
	var art = $(".add-hover h1 b").text();
	$(".add-hover .add-change ul").html("");
	$(".add-hover h1").html("添加<b>"+art+"</b>的相关文字");
	var html = "";
	//html += '<dt><span>标题</span><input type="text" class="title" /></dt>';
	html += '<dt><span>艺术家</span><input type="text" class="author" readonly value="'+art+'"/></dt>';
	html += '<dt class="radio"><span>类　别</span><input type="radio" name="type" value="1" id="checked"/>简历<input type="radio" name="type" value="2"/>评论<input type="radio" name="type" value="3"/>自诉</dt>';
	html += '<dt><span>内　容</span><textarea name="" id="" cols="150" rows="5" class="content"></textarea></dt>';
	html += '<input id="save_words" type="button" onclick="save_words('+a+','+b+')" value="提　交"/>';


	$(".add-hover .add-change ul").append(html);
	$("div.left-return").attr("onclick","Initialization()");
	$( "#checked" ).prop( "checked", true );
}





// 添加视频
	var formform = $(".formform").html();

	function add_video(a,b){
		var art = $(".add-hover h1 b").text();
		$(".add-hover h1").html("添加<b>"+art+"</b>的相关视频");

		$(".add-hover .add-change ul").html("");
		var html = "";
		//html += '<form action="" method="post" name="myform">'+formform+'</form>';

		html += '<label for="iptfileupload"><img src="/t/Public/Home/img/art/video.jpg" alt="" id="imgger">点击图片<br>添加视频封面</label>';
		html += '<div class="add_vedio">';
		//html += '<dt><span>分类</span> <select name="select" id="select_k1"> <option value="1">全部</option> <option value="2">分类2</option> <option value="3">分类3</option> </select> </dt> ';
		html += '<dt><span>链接</span><input type="text" class="link" placeholder="视频的外部链接网址"/></dt>';
		html += '<dt><span>标题</span><input type="text" class="title" placeholder="视频的标题"/></dt>';

		html += '<dt><span>简介</span><textarea name="" id="" cols="150" rows="5" class="content"></textarea></dt>';
		html += '</div>';
		html += '<hr style="border:0;clear:both;"/>';
		html += '<input id="save_words" type="button" onclick="save_vedio('+a+','+b+')" value="提　交"/>';

		$(".add-hover .add-change ul").append(html);
		$("div.left-return").attr("onclick","Initialization()");

	}


	// 添加并显示图片
	function getPath(obj,fileQuery,transImg) {

	   var imgSrc = '', imgArr = [], strSrc = '' ;
	 
	   if(window.navigator.userAgent.indexOf("MSIE")>=1){ // IE浏览器判断
		    if(obj.select){
			     obj.select();
			     var path=document.selection.createRange().text;
			     //alert(path) ;
			     obj.removeAttribute("src");
			     imgSrc = fileQuery.value ;
			     imgArr = imgSrc.split('.') ;
			     strSrc = imgArr[imgArr.length - 1].toLowerCase() ;
			     if(strSrc.localeCompare('jpg') === 0 || strSrc.localeCompare('jpeg') === 0 || strSrc.localeCompare('gif') === 0 || strSrc.localeCompare('png') === 0){
			      obj.setAttribute("src",transImg);
			      obj.style.filter=
			       "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path+"', sizingMethod='scale');"; // IE通过滤镜的方式实现图片显示
			     }else{
			      throw new Error('文件类型出错，请重新上传！');
			     }
		    }else{
			     // alert(fileQuery.value) ;
			     imgSrc = fileQuery.value ;
			     imgArr = imgSrc.split('.') ;
			     strSrc = imgArr[imgArr.length - 1].toLowerCase() ;
			     if(strSrc.localeCompare('jpg') === 0 || strSrc.localeCompare('jpeg') === 0 || strSrc.localeCompare('gif') === 0 || strSrc.localeCompare('png') === 0){
			      obj.src = fileQuery.value ;
			     }else{
			      throw new Error('文件类型出错，请重新上传！') ;
			     }
		 
		    }
	 
	   } else{
		    var file =fileQuery.files[0];
		    var reader = new FileReader();
		    reader.onload = function(e){
		 
		     imgSrc = fileQuery.value ;
		     imgArr = imgSrc.split('.') ;
		     strSrc = imgArr[imgArr.length - 1].toLowerCase() ;
		     if(strSrc.localeCompare('jpg') === 0 || strSrc.localeCompare('jpeg') === 0 || strSrc.localeCompare('gif') === 0 || strSrc.localeCompare('png') === 0){
		      	obj.setAttribute("src", e.target.result) ;
		     }else{
		      throw new Error('文件类型出错，请重新上传！') ;
		     }
	 
	     // alert(e.target.result); 
	    }
	    reader.readAsDataURL(file);
	   }

	}

	function show_img(){

		//以下即为完整客户端路径
		var file_img=document.getElementById("imgger"),
		iptfileupload = document.getElementById('iptfileupload') ;
		getPath(file_img,iptfileupload,file_img) ;

	}




// 关闭

function close_add(){

	var clo = '';
	clo += '<div class="close-angin-fixed">';
	clo += '<div class="close-angin-con">';
	clo += '<h2>是否确认放弃添加</h2>';
	clo += '<input type="button" onclick="close_angin()" value="确认">';
	clo += '<input class="in1" type="button" onclick="cancel_angin()" value="取消">';
	clo += '</div></div>';

	$("body").append(clo);
}


function close_angin(){

	$(".add-hover").hide();
	$(".close-angin-fixed").remove();

}


function cancel_angin(){
	$(".close-angin-fixed").remove();
}


































